package com.netcracker.studportal.server.model;
import java.io.Serializable;

import javax.persistence.*;

import org.json.simple.JSONObject;

@Entity
@Table(name = "Exam_results")
public class ExamWithResult implements Serializable {
	@Id
	@Column(name= "exam_id")	
	private Long exam_id;
	@Id
	@Column(name= "student_id")	
	private Long student_id;
	
	@Column(name= "mark")
	private Integer mark;
	
	@Column(name= "note")
	private String note;
	
	@ManyToOne(cascade=CascadeType.ALL)
	@JoinColumn(name = "exam_id",insertable = false, updatable = false)
	private Exam exam;
	
	//getters
	
	public Long getExam_id(){return this.exam_id;}
	
	public Long getStudent_id(){return this.student_id;}
	
	public Integer getMark(){return this.mark;}
	
	public String getNote(){return this.note;}
	
	public Exam getExam(){return this.exam;}
	
	//setters
	
	public void setExam_id(Long exam_id) {this.exam_id= exam_id;}	
	
	public void setStudent_id(Long student_id) {this.student_id= student_id;}
	
	public void setMark(Integer mark) {this.mark= mark;}
	
	public void setNote(String note) {this.note= note;}
	
	public void setExam(Exam exam){this.exam=exam;}
	
	
	public JSONObject kJSON(){
		JSONObject obj=new JSONObject();
		if(this.exam_id!=null) obj.put("exam_id", this.exam_id.toString());
		if(this.student_id!=null) obj.put("student_id", this.student_id.toString());
		if(this.mark!=null) obj.put("mark", this.mark.toString());
		obj.put("note", this.note);
		if(this.exam!=null){
			obj.put("exam", this.exam.kJSON());
		}
		
		return obj;	
	}
	
}
